//
//  NewsflashRecommendDetailCell.m
//  AutoHome
//
//  Created by wqh on 15-5-15.
//  Copyright (c) 2015年 Wqh. All rights reserved.
//

#import "NewsflashRecommendDetailCell.h"

#define kPicWidth ([UIScreen mainScreen].bounds.size.width-20)

@implementation NewsflashRecommendDetailCell

- (void)awakeFromNib {
    // Initialization code
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

}

- (void)showDataWithModel:(NewsflashDetailModel *)model {
   
    
    
    if (model.headimg.length>0) {
        
        NSMutableString *headstr = [NSMutableString stringWithString:model.headimg];
        NSRange range = [headstr rangeOfString:@"i"];
        [headstr replaceCharactersInRange:range withString:@"app"];
        if (range.location == NSNotFound) {
            self.headerImg.image = [UIImage imageNamed:@"authorhead"];
        }else {
            [self.headerImg sd_setImageWithURL:[NSURL URLWithString:headstr] placeholderImage:nil];
        }

    }else {
        self.headerImg.image = [UIImage imageNamed:@"authorhead"];
    }
    
    self.contentLabel.text = model.content;
    self.nameLabel.text = model.authorname;
    self.timeLabel.text = model.publishtime;
    
   
    
    //添加图片
    NSArray *array = model.attachments;
    
    [[self.imagesArrView subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)];
    
    if (model.attachments .count  > 0) {
        int i = 0;
        //记录下y坐标；
        CGFloat y = 0;
        for (NSDictionary *picInfo in array) {
            
            CGFloat pic_width = [picInfo[@"width"] floatValue];
            CGFloat pic_height = [picInfo[@"height"] floatValue ];
            CGFloat height = kPicWidth * pic_height /pic_width;
            
            UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, y+10, kPicWidth, height)];
            
            [imageView sd_setImageWithURL:[NSURL URLWithString:picInfo[@"picurl"] ] placeholderImage:[UIImage imageNamed:@"black_default_640_320"]];
            [self.imagesArrView addSubview:imageView];
            imageView.backgroundColor = [UIColor redColor];
            y += height+10;
            i++;
        }
    }
    
   
    
    
}

@end
